﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Shopping.BLL;
using Shopping.Common;
using Shopping.Model;

public partial class Home_AS_MyFavoriteCommon : BaseUserPage
{
    private readonly UserFavoriteManage _userFavoriteManage = new UserFavoriteManage();
    protected List<UserFavorites> _userFavorites = new List<UserFavorites>();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string action = Request.QueryString["Action"] as string;
            switch (action.ToLower())
            {
                case "showuserfavorites":   //
                    ShowUserFavorites();
                    break;
                case "delshopping":
                    DelUserFavorite();
                    break;
                case "deleteallfavorites":
                    DeleteAllUserFavorite();
                    break;
            }

        }
    }
    private void DeleteAllUserFavorite()
    {
        ReturnValue result = new ReturnValue();// _userFavoriteManage.Clear(_userFavoriteManage.GetShoppingCartCookieName(_Users.UserID));
        result.Result = ResultType.Fail;
        result.Message = "";
        Response.Write(JSONHelper.ObjectToJson(result));
        Response.End();
    }
    private void DelUserFavorite()
    {
        var id = Utility.P<int>("id");
        ReturnValue result = null;
        if (id <= 0)
        {
            result = new ReturnValue(ResultType.Fail, "请选择要删除的商品");
        }
        else
        {
            result = _userFavoriteManage.Delete(0, id);
        }
        Response.Write(JSONHelper.ObjectToJson(result));
        Response.End();
    }
    private void ShowUserFavorites()
    {
        _userFavorites = null;

    }
}
